import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';



import '../AppConfig/Config.dart';
import '../AppConfig/LocalStorage.dart';
import '../AppConfig/RouteAct.dart';
import 'ActivePage.dart';
import 'BusinessPage.dart';
import 'ChatPage.dart';
import 'NotificationPage.dart';

class MessageCenter extends StatefulWidget {
  const MessageCenter({super.key});

  @override
  State<MessageCenter> createState() => _MessageCenterState();
}

class _MessageCenterState extends State<MessageCenter> {
  int index=2;
  String phoneNum="";
  String userId="";
  String imToken="";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getPhoneNum();
  }
  Future<void>  getPhoneNum() async {
    phoneNum=(await PhoneNumManager.getPhone())!;
    userId =(await UserIdManager.getUserID())!;
    imToken =(await IMIdManager.getIMID())!;
  }
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        title:   Container(
          padding: EdgeInsets.only(left:20.w,right: 20.w,top: 10.h),
          height: 40.5.h,
          // color: Colors.white,
          width: screenSize.width,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              GestureDetector(
                child:  Column(
                  children: [
                    Text("聊天",style: TextStyle(color: index==1?MyColors.themeColor: Colors.black,fontSize: 14.sp),),
                    SizedBox(height: 10.h,),
                    if(index==1)
                    Container(width: 20.w,height: 2.h,color: index==1?MyColors.themeColor:Colors.white,),
                  ],
                ),
                onTap: (){
                  // Navigator.push( context, FadeRoute(page:ChatPage(phoneNum: phoneNum,)));
                  setState(() {
                    index=1;
                  });
                },
              ),

              GestureDetector(
                child:  Column(
                  children: [
                    Text("通知",style: TextStyle(color: index==2?MyColors.themeColor: Colors.black,fontSize: 14.sp),),
                    SizedBox(height: 10.h,),
                    if(index==2)
                    Container(width: 20.w,height: 2.h,color: index==2?MyColors.themeColor:Colors.white,),
                  ],
                ),
                onTap: (){
                  setState(() {
                    index=2;
                  });
                },
              ),
              GestureDetector(
                child:  Column(
                  children: [
                    Text("活动",style: TextStyle(color: index==3?MyColors.themeColor: Colors.black,fontSize: 14.sp),),
                    SizedBox(height: 10.h,),
                    if(index==3)
                    Container(width: 20.w,height: 2.h,color: index==3?MyColors.themeColor:Colors.white,),
                  ],
                ),
                onTap: (){
                  setState(() {
                    index=3;
                  });
                },
              ),
              GestureDetector(
                child:  Column(
                  children: [
                    Text("业务",style: TextStyle(color: index==4?MyColors.themeColor: Colors.black,fontSize: 14.sp),),
                    SizedBox(height: 10.h,),
                    if(index==4)
                    Container(width: 20.w,height: 2.h,color: index==4?MyColors.themeColor:Colors.white,),
                  ],
                ),
                onTap: (){
                  setState(() {
                    index=4;
                  });
                },
              ),
              SizedBox(),
            ],
          ),
        ),
      ),
      body: ListView(
        children: [

          Divider(height: 1.h,color: MyColors.backgreyColor,),
          Container(
            width: screenSize.width,
            height: screenSize.height-90.h,
            // child: HomeTabBar(),
            child:index==1?ChatPage(phoneNum: phoneNum, userId: userId, imToken:imToken,):index==2?NotificationPage():index==3?ActivePage():BusinessPage(),
          )
        ],
      ),
    );
  }
}
